package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.ef.constant.StatusType;
import com.ef.dao.MarketingPolicyDao;
import com.ef.domain.MarketingPolicy;
import com.ef.domain.Team;
import com.ef.service.MarketingPolicyService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class MarketingPolicyServiceImpl extends BaseServiceImpl implements
		MarketingPolicyService {

	private MarketingPolicyDao marketingPolicyDao;

	public PaginationSupport<MarketingPolicy> findByExample(
			CustomExample<MarketingPolicy> example, int startIndex, int pageSize) {

		return marketingPolicyDao.findPageByExample(example, startIndex,
				pageSize);
	}

	public void saveOrUpdate(MarketingPolicy entity) {
		marketingPolicyDao.saveOrUpdate(entity);
	}

	public void delete(MarketingPolicy entity) {
		entity.setStatus(StatusType.INVALID);
		marketingPolicyDao.saveOrUpdate(entity);
	}

	public MarketingPolicy findById(Long id) {
		return marketingPolicyDao.findById(id);
	}

	public List<MarketingPolicy> findAll() {
		DetachedCriteria criteria = DetachedCriteria
				.forClass(MarketingPolicy.class);
		criteria.add(Restrictions.eq("status", StatusType.VALID));
		return marketingPolicyDao.findAllByCriteria(criteria);

	}

	public List<MarketingPolicy> findAllByTeam(Team team) {
		DetachedCriteria criteria = DetachedCriteria
				.forClass(MarketingPolicy.class);
		criteria.add(Restrictions.eq("team",team));
		criteria.add(Restrictions.eq("status", StatusType.VALID));
		return marketingPolicyDao.findAllByCriteria(criteria);

	}

	public MarketingPolicyDao getMarketingPolicyDao() {
		return marketingPolicyDao;
	}

	public void setMarketingPolicyDao(MarketingPolicyDao marketingPolicyDao) {
		this.marketingPolicyDao = marketingPolicyDao;
	}

}
